home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Produtividade / OpenOffice.org 2.0.1 / openofficeorg4.cab / test_hexoct.py < prev    next >
Text File  |  2005-11-19  |  5KB  |  125 lines

  1. """Test correct treatment of hex/oct constants.
  2.  
  3. This is complex because of changes due to PEP 237.
  4.  
  5. Some of these tests will have to change in Python 2.4!
  6. """
  7.  
  8. import sys
  9. platform_long_is_32_bits = sys.maxint == 2147483647
  10.  
  11. import unittest
  12. from test import test_support
  13.  
  14. import warnings
  15. warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
  16.                         "<string>")
  17.  
  18. class TextHexOct(unittest.TestCase):
  19.  
  20.     def test_hex_baseline(self):
  21.         # Baseline tests
  22.         self.assertEqual(0x0, 0)
  23.         self.assertEqual(0x10, 16)
  24.         if platform_long_is_32_bits:
  25.             self.assertEqual(0x7fffffff, 2147483647)
  26.         else:
  27.             self.assertEqual(0x7fffffffffffffff, 9223372036854775807)
  28.         # Ditto with a minus sign and parentheses
  29.         self.assertEqual(-(0x0), 0)
  30.         self.assertEqual(-(0x10), -16)
  31.         if platform_long_is_32_bits:
  32.             self.assertEqual(-(0x7fffffff), -2147483647)
  33.         else:
  34.             self.assertEqual(-(0x7fffffffffffffff), -9223372036854775807)
  35.         # Ditto with a minus sign and NO parentheses
  36.         self.assertEqual(-0x0, 0)
  37.         self.assertEqual(-0x10, -16)
  38.         if platform_long_is_32_bits:
  39.             self.assertEqual(-0x7fffffff, -2147483647)
  40.         else:
  41.             self.assertEqual(-0x7fffffffffffffff, -9223372036854775807)
  42.  
  43.     def test_hex_unsigned(self):
  44.         # This test is in a <string> so we can ignore the warnings
  45.         exec """if 1:
  46.         if platform_long_is_32_bits:
  47.             # Positive-looking constants with negavive values
  48.             self.assertEqual(0x80000000, -2147483648L)
  49.             self.assertEqual(0xffffffff, -1)
  50.             # Ditto with a minus sign and parentheses
  51.             self.assertEqual(-(0x80000000), 2147483648L)
  52.             self.assertEqual(-(0xffffffff), 1)
  53.             # Ditto with a minus sign and NO parentheses
  54.             # This failed in Python 2.2 through 2.2.2 and in 2.3a1
  55.             self.assertEqual(-0x80000000, 2147483648L)
  56.             self.assertEqual(-0xffffffff, 1)
  57.         else:
  58.             # Positive-looking constants with negavive values
  59.             self.assertEqual(0x8000000000000000, -9223372036854775808L)
  60.             self.assertEqual(0xffffffffffffffff, -1)
  61.             # Ditto with a minus sign and parentheses
  62.             self.assertEqual(-(0x8000000000000000), 9223372036854775808L)
  63.             self.assertEqual(-(0xffffffffffffffff), 1)
  64.             # Ditto with a minus sign and NO parentheses
  65.             # This failed in Python 2.2 through 2.2.2 and in 2.3a1
  66.             self.assertEqual(-0x8000000000000000, 9223372036854775808L)
  67.             self.assertEqual(-0xffffffffffffffff, 1)
  68.         \n"""
  69.  
  70.     def test_oct_baseline(self):
  71.         # Baseline tests
  72.         self.assertEqual(00, 0)
  73.         self.assertEqual(020, 16)
  74.         if platform_long_is_32_bits:
  75.             self.assertEqual(017777777777, 2147483647)
  76.         else:
  77.             self.assertEqual(0777777777777777777777, 9223372036854775807)
  78.         # Ditto with a minus sign and parentheses
  79.         self.assertEqual(-(00), 0)
  80.         self.assertEqual(-(020), -16)
  81.         if platform_long_is_32_bits:
  82.             self.assertEqual(-(017777777777), -2147483647)
  83.         else:
  84.             self.assertEqual(-(0777777777777777777777), -9223372036854775807)
  85.         # Ditto with a minus sign and NO parentheses
  86.         self.assertEqual(-00, 0)
  87.         self.assertEqual(-020, -16)
  88.         if platform_long_is_32_bits:
  89.             self.assertEqual(-017777777777, -2147483647)
  90.         else:
  91.             self.assertEqual(-0777777777777777777777, -9223372036854775807)
  92.  
  93.     def test_oct_unsigned(self):
  94.         # This test is in a <string> so we can ignore the warnings
  95.         exec """if 1:
  96.         if platform_long_is_32_bits:
  97.             # Positive-looking constants with negavive values
  98.             self.assertEqual(020000000000, -2147483648L)
  99.             self.assertEqual(037777777777, -1)
  100.             # Ditto with a minus sign and parentheses
  101.             self.assertEqual(-(020000000000), 2147483648L)
  102.             self.assertEqual(-(037777777777), 1)
  103.             # Ditto with a minus sign and NO parentheses
  104.             # This failed in Python 2.2 through 2.2.2 and in 2.3a1
  105.             self.assertEqual(-020000000000, 2147483648L)
  106.             self.assertEqual(-037777777777, 1)
  107.         else:
  108.             # Positive-looking constants with negavive values
  109.             self.assertEqual(01000000000000000000000, -9223372036854775808L)
  110.             self.assertEqual(01777777777777777777777, -1)
  111.             # Ditto with a minus sign and parentheses
  112.             self.assertEqual(-(01000000000000000000000), 9223372036854775808L)
  113.             self.assertEqual(-(01777777777777777777777), 1)
  114.             # Ditto with a minus sign and NO parentheses
  115.             # This failed in Python 2.2 through 2.2.2 and in 2.3a1
  116.             self.assertEqual(-01000000000000000000000, 9223372036854775808L)
  117.             self.assertEqual(-01777777777777777777777, 1)
  118.         \n"""
  119.  
  120. def test_main():
  121.     test_support.run_unittest(TextHexOct)
  122.  
  123. if __name__ == "__main__":
  124.     test_main()
  125.